﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel;
using System.Web.Security;
// services
using MovieCtrlService;
using AuthService;

public partial class Account_Login : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
	}

	protected void LoginSubmitClick(object sender, EventArgs e)
	{
		CinemaServiceClient service = new CinemaServiceClient();
		bool success = service.Login(LoginUser.UserName, LoginUser.Password);
		if (success)
		{
			FormsAuthentication.SetAuthCookie(LoginUser.UserName, false /* createPersistentCookie */);
            Session["Username"] = LoginUser.UserName; 
			Response.Redirect("~/User/Default.aspx");
		}
		else
		{
			Session["Username"] = null;
			LoginUser.FailureText = "Wrong user name or password!";
		}
		//Response.Write(@"<script language='javascript'>alert('" + result + "');</script>");
	}
}
